#include "debugOutput.h"
#include <QLabel>

namespace dbg{

	void ShowImage(QImage &img,QString str){
#ifdef DEBUG_OUTPUT
		ShowImage(QPixmap::fromImage(img),str);
#endif
	}

        void ShowImage(const QPixmap &img,QString str){
#ifdef DEBUG_OUTPUT
		QLabel* lb = new QLabel;
		lb->setWindowTitle(str);
		lb->setPixmap(img);
		lb->setAttribute(Qt::WA_DeleteOnClose);
		lb->setScaledContents(true);
		lb->show();
#endif	
	}


        void ShowRedChannel(const QImage &img,QString str){
#ifdef DEBUG_OUTPUT
		QImage res(img.width(),img.height(),QImage::Format_RGB32);
		for(int x = 0; x < img.width(); x++)
			for(int y = 0; y < img.height(); y++){
				int color = qRed(img.pixel(x,y));
				res.setPixel(x,y,qRgb(color,color,color));
			}
		QLabel* lb = new QLabel;
		lb->setWindowTitle(str);
		lb->setPixmap(QPixmap::fromImage(res));
		lb->setAttribute(Qt::WA_DeleteOnClose);
		lb->setScaledContents(true);
		lb->show();
#endif
	}
	void ShowRedChannel(QPixmap &pixmap,QString str){
#ifdef DEBUG_OUTPUT
		ShowRedChannel(pixmap.toImage(),str);
#endif
	}

	//////////////////Green
        void ShowGreenChannel(const QImage &img,QString str){
#ifdef DEBUG_OUTPUT
		QImage res(img.width(),img.height(),QImage::Format_RGB32);
		for(int x = 0; x < img.width(); x++)
			for(int y = 0; y < img.height(); y++){
				int color = qGreen(img.pixel(x,y));
				res.setPixel(x,y,qRgb(color,color,color));
			}
		QLabel* lb = new QLabel;
		lb->setWindowTitle(str);
		lb->setPixmap(QPixmap::fromImage(res));
		lb->setAttribute(Qt::WA_DeleteOnClose);
		lb->setScaledContents(true);
		lb->show();
#endif
	}
	void ShowGreenChannel(QPixmap &pixmap,QString str){
#ifdef DEBUG_OUTPUT
		ShowGreenChannel(pixmap.toImage(),str);
#endif
	}


	///////////Blue 
        void ShowBlueChannel(const QImage &img,QString str){
#ifdef DEBUG_OUTPUT
		QImage res(img.width(),img.height(),QImage::Format_RGB32);
		for(int x = 0; x < img.width(); x++)
			for(int y = 0; y < img.height(); y++){
				int color = qBlue(img.pixel(x,y));
				res.setPixel(x,y,qRgb(color,color,color));
			}
		QLabel* lb = new QLabel;
		lb->setWindowTitle(str);
		lb->setPixmap(QPixmap::fromImage(res));
		lb->setAttribute(Qt::WA_DeleteOnClose);
		lb->setScaledContents(true);
		lb->show();
#endif
	}
	void ShowBlueChannel(QPixmap &pixmap,QString str){
#ifdef DEBUG_OUTPUT
                ShowBlueChannel(pixmap.toImage(),str);
#endif
	}

        void ScaleImageBright(const QImage& img,QString str){
#ifdef DEBUG_OUTPUT
		QImage scale("Resources/scale.bmp");
		int maxVal = 0;
		QImage image(img);
		image.fill(Qt::black);
		for(int x = 0;x < img.width(); x++){
			for(int y = 0;y < img.height(); y++){
				if(maxVal<(img.pixel(x,y)&0x00FFFFFF))
					maxVal = (img.pixel(x,y)&0x00FFFFFF);
			}
		}	
		float coeft = 999.0/(float)maxVal;
		for(int x = 0;x < img.width(); x++){
			for(int y = 0;y < img.height(); y++){
				if(img.pixel(x,y)&0x00FFFFFF)
					image.setPixel(x,y,scale.pixel(1,coeft*(img.pixel(x,y)&0x00FFFFFF)));
			}
		}
                ShowImage(image,str);
#endif
	}
}

